package main

import (
	"fmt"
	"math/rand"
)

func main() {
	//region 数组
	//fmt.Print("hello world \n")
	//fmt.Print("Test 数组集合 \n")
	//num := GetListMax(GetList(3))
	//fmt.Printf("Max Nun Is %d \n", num)
	//fmt.Print("坑爹呢 数组长度必须提前定义，而且不同长度还被认为是不通类型 \n")
	//endregion

	//region 切片
	//fmt.Println(firstQuarter);
	//fmt.Println(secondQuarter);
	//fmt.Println(thirdQuarter);
	//fmt.Println(fourthQuarter);
	//fmt.Println(q);
	//fmt.Println(months[:8])
	//fmt.Println(GetMonth(1, 4))
	//GetNum(5)
	//endregion

	//region Map
	totalMonth[13] = "unknown"
	var monthtemp = "unknown value"
	monthtemp, ok := totalMonth[13]
	if ok {
		totalMonth[13] = monthtemp
		fmt.Println(totalMonth[13])
		totalMonth[13] += ",it is not right"
		fmt.Println(totalMonth[13])
	}
	for key, value := range totalMonth {
		fmt.Printf("%d\t%s\n", key, value)
	}
	//endregion
}

//region 数组循序

func GetList(length int) [3]int {
	var result [3]int
	if length > 0 {
		for i := 0; i < length; i++ {
			result[i] = rand.Intn(100)
		}
		return result
	} else {
		return result
	}
}

//获取集合最大值
func GetListMax(list [3]int) int {
	temp := 0
	if len(list) <= 0 {
		return temp
	}
	for a := 0; a < len(list); a++ {
		if list[a] > temp {
			temp = list[a]
		}
	}
	return temp
}

//endregion

//region Slice 切片
var months = [...]string{1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July", 8: "August", 9: "September", 10: "October", 11: "November", 12: "December"}
var firstQuarter = months[1:4]
var secondQuarter = months[4:7]
var thirdQuarter = months[7:10]
var fourthQuarter = months[10:13]
var q = months[0:2]

func GetMonth(x, y int) []string {
	var result []string
	for i := x; i < x+y; i++ {
		result = append(result, months[i])
	}
	return result
}

func GetNum(length int) {
	var x, y []int
	for i := 0; i < length; i++ {
		y = append(x, i)
		fmt.Printf("%d cap= %d\t%v\n", i, cap(y), y)
		x = y
	}
}

//endregion

//region Map
var totalMonth = map[int]string{
	1: "January", 2: "February", 3: "March", 4: "April", 5: "May", 6: "June", 7: "July", 8: "August", 9: "September", 10: "October", 11: "November", 12: "December",
}

//endregion
